import math  
maxlen = 1001
maxn=1  
maxD=2  
for D in range(2,maxlen):  
    tmp=math.sqrt(D)  
    tmp=int(tmp)  
    if tmp*tmp==D:  
        continue  
  
    m=0  
    d=1  
    a=tmp  
    #print(a)  
    n1=1  
    d1=0  
    num=a  
    den=1  
  
    while num*num-D*den*den!=1:  
        m=int(a*d-m)  
        d=int((D-m*m)/d)  
        a=int((tmp+m)/d)  
  
        n2=n1  
        n1=num  
        d2=d1  
        d1=den  
  
        num=int(a*n1+n2)  
        den=int(a*d1+d2)  
    if num > maxn: 
        print "x=",num, "d=",D, "y=",den 
        maxn=num  
        maxD=D  
print(maxD)  